package begin 
{
	import org.airmvc.Controller;
	import org.airmvc.ModulesManager;
	import utils.T;
	import vo.GeneralVO;
	import vo.SystemVO;
	
	/**
	 * 开始选择进度，关卡和君主模块
	 * @author WLDragon 2014-02-28
	 */
	public class BeginC extends Controller 
	{
		
		public function BeginC() 
		{
			super();
		}
		
		override protected function addListeners():void 
		{
			receive(ORDER, handleOrder);
			receive(CHOOSE_MONARCH, handleChoose);
			receive(CHECK_MONARCH,handleCheck);
		}
		
		private function handleCheck(g:GeneralVO):void 
		{
			broadcast(Nws.GENERAL_OPEN,[g],0);
		}
		
		private function handleChoose(id:int):void 
		{
			
			broadcast(Nws.BEGIN_CHOOSE_MONARCH, id);
			
			broadcast(Nws.STARTUP_STRATEGY, Nws.STARTUP_STRATEGY);
			broadcast(Nws.STARTUP_MENU, Nws.STARTUP_MENU);
			//broadcast(Nws.STARTUP_DIALOGUE, Nws.STARTUP_DIALOGUE);
			broadcast(Nws.STARTUP_INFOMATION, Nws.STARTUP_INFOMATION);
			broadcast(Nws.STARTUP_REPORT, Nws.STARTUP_REPORT);
			
			//关闭武将信息面板
			broadcast(Nws.STARTUP_GENERAL,false);
			
			send(SHOW_OR_HIDE);
			ModulesManager.remove(Nws.STARTUP_BEGIN);
		}
		
		private function handleOrder(param:String):void 
		{
			switch (param) 
			{
				case "start":
					send(OPEN_SECOND_MENU);
				break;
				case "read":
					if (T.db.load())
					{
						Lyr.setBackGround(0xFFC8B9);
						var sys:SystemVO = T.db.getRecord(Cnt.VO_SYSTEM, 1) as SystemVO;
						handleChoose(sys.playerID);
					}
					else
					{
						send(OPEN_SECOND_MENU);
					}
					//broadcast(Nws.BEGIN_LOAD_GAME);
				break;
				case "easy":
					broadcast(Nws.BEGIN_CHOOSE_LEVEL,4);
					send(ENTER_MONARCH);
				break;
				case "normal":
					broadcast(Nws.BEGIN_CHOOSE_LEVEL,2);
					send(ENTER_MONARCH);
				break;
				case "difficult":
					broadcast(Nws.BEGIN_CHOOSE_LEVEL,1);
					send(ENTER_MONARCH);
				break;
			}
		}
				
		override protected function startup(... args):void 
		{
			//初始化视图
			view = new BeginV();
			registerView(view);
			send(SHOW_OR_HIDE);
		}
		
		/**打开或关闭视图*/
		static public const SHOW_OR_HIDE:String = "show_or_hide";
		/**指令消息*/
		static public const ORDER:String = "order";
		/**打开进入游戏的第二个菜单*/
		static public const OPEN_SECOND_MENU:String = "open_second_menu";
		/**进入选择君主面板*/
		static public const ENTER_MONARCH:String = "enter_monarch";
		/**选择君主*/
		static public const CHOOSE_MONARCH:String = "choose_monarch";
		/**查看君主消息*/
		static public const CHECK_MONARCH:String = "check_monarch";
	}
	
}